package com.ebraga.trackerclub.android.manager.core;

import com.ebraga.trackerclub.android.dao.api.UserDao;
import com.ebraga.trackerclub.android.dao.entity.UserAndroid;
import com.ebraga.trackerclub.android.exception.BackofficeDBConnectionException;
import com.ebraga.trackerclub.android.exception.dao.BackofficeDaoException;
import com.ebraga.trackerclub.android.exception.dao.BackofficeIllegalArgumentDaoException;
import com.ebraga.trackerclub.android.exception.manager.BackofficeIllegalArgumentManagerException;
import com.ebraga.trackerclub.android.exception.manager.BackofficeManagerException;
import com.ebraga.trackerclub.android.manager.api.UserManager;
import com.ebraga.trackerclub.android.util.DLog;

public abstract class UserManagerImpl implements UserManager {
	
	protected UserDao userDao;
	
	protected void setUserDao (UserDao userDao){
		this.userDao = userDao;
	}

	@Override
	public UserAndroid getUser(String login)
			throws BackofficeIllegalArgumentManagerException,
			BackofficeDBConnectionException , BackofficeManagerException {
		
		UserAndroid userA;
		
		if (login == null){
			throw new BackofficeIllegalArgumentManagerException("Usuario invalido");			
		}
		try{
			userA = userDao.getUser(login);
		}catch (BackofficeDBConnectionException db){
			DLog.e(db);
			throw new BackofficeDBConnectionException("Erro ao conectar banco de dados");
		}catch (BackofficeIllegalArgumentDaoException ie){
			DLog.e(ie);
			throw new BackofficeIllegalArgumentManagerException("Usuario invalido");	
		}catch (BackofficeDaoException de){
			DLog.e(de);
			throw new BackofficeManagerException("Erro ao recuperar usuario");
		}
		
		return userA;
	}

}
